#ifndef POPULARITYMETHOD_H_
#define POPULARITYMETHOD_H_

#include <vector>
#include <map>

#include "../NewUserMethod.h"

class PopularityMethod: public NewUserMethod {
private:
	typedef std::map<std::pair<int, int>, int> matrix;
	const matrix& dataset;
public:
	PopularityMethod(const matrix& dataset) :
		dataset(dataset) {
	}

	virtual std::vector<int> getItens() {
		std::map<int, int> count;
		std::multimap<int, int> popularity;
		std::vector<int> itens;
		for (matrix::const_iterator it = dataset.begin(); it != dataset.end(); it++)
			if (it->second != 0)
				count[it->first.second]++;
		for (std::map<int, int>::const_iterator it = count.begin(); it
				!= count.end(); it++)
			popularity.insert(std::make_pair(it->second, it->first));
		for (std::multimap<int, int>::const_iterator it = popularity.begin(); it
				!= popularity.end(); it++)
			itens.push_back(it->second);
		return itens;
	}
};

#endif /* POPULARITYMETHOD_H_ */
